

*************************
 General considerations
*************************
Why the ReadWrite sub is called IV? What do you think about RW (read/write)?


*************************
Form_Main
************************* 
In the Form Main this line is commented:  
  'IVmode = False : SaveLoad_INI()
And also in the Form Equalizers:  
  'IVmode = False : SaveLoadEqualizer()
  'IVmode = False : SaveLoadLinearizer()

I loose some params every time the program is not closed correctly (during the debug for example) 
Can you please correct your IV functions in order to restore the original LostFocus ?


*************************
Form_Main
************************* 
There are 4 new labels:
Label_Zoom
Label_Vert1
Label_Vert2
Label_Vert3

And a new "verticalize" function:
Private Sub PaintVerticalText(ByVal sender As Object, ByVal e As PaintEventArgs) Handles Label_Vert1.Paint, _
                                                                                         Label_Vert2.Paint, _
                                                                                         Label_Vert3.Paint
    Dim c As Control = CType(sender, Control)
    e.Graphics.RotateTransform(-90)
    e.Graphics.DrawString(c.Tag.ToString, c.Font, New SolidBrush(c.ForeColor), _
                          -c.Height, 0, StringFormat.GenericDefault)
End Sub


*************************
Form_Main
************************* 
The following line has been added to many functions to speed-up visualization 
TimerDraw.Interval = 100 ' show changes immediately


*************************
 Class Spectrometer
************************* 
You changed the function GetValidPulses to return a ULong value
but this generates errors with negative values.

    Friend Function GetValidPulses() As ULong
        GetValidPulses = WaveRec.TotalPulses
        For i As Int32 = 0 To mFirstBinIndex - 1
            GetValidPulses -= CULng(WaveRec.Bins(i))
        Next
        If GetValidPulses < 0 Then GetValidPulses = 0
    End Function

This is the corrected function.

    Friend Function GetValidPulses() As ULong
        Dim PulsesToSubtract As ULong = 0
        For i As Int32 = 0 To mFirstBinIndex - 1
            PulsesToSubtract += CULng(WaveRec.Bins(i))
        Next
        If WaveRec.TotalPulses > PulsesToSubtract Then
            Return WaveRec.TotalPulses - PulsesToSubtract
        Else
            Return 0
        End If
    End Function


*************************
Form_Main
************************* 
Changed MinimumSize (750 x 640) - To make place for the new "Gaussian deconvolution" PANEL

Resized manually the TAB controls

Form_Main.MaximumSize = (1024 x 720) 
To avoid people making incredible large images 
and to avoid to explain, all the time, why the Scope and Equalizers are not visible.

Two new buttons to help isotope selections
btn_DeselectIsotopes  "Deselect all isotopes"
btn_ExtendRows  "Extend to all rows"


*************************
WaveRecorder
   DataArrived
*************************
   			Dim denom As Single = (mp1 - BaseLine3) * 100
                        If denom <= 0 Then denom = 0.000001
                        mScopeNoise1 = CInt(noise1 / denom)
                        mScopeNoise2 = CInt(noise2 / denom)
                        mScopeRR = ScopeRR
                        mScopeBaseLine1 = BaseLine1
                        mScopeBaseLine2 = BaseLine2
                        mScopeBaseLine3 = BaseLine3
                        mScopeSlope = (BaseLine2 - BaseLine1) / denom
                        mGetScopeSamples = False
                        mValidScopeSamples = True
                        mRefreshPulsePicture = True

*************************
Form_Main
     SelectIsotopeLine
*************************
Now the function is executed also if isotope list is not visible
The last three lines of the function are required to ensure the centering of thr selected isotope 

*************************
Form_Main
     PBox_Spectrum_DoubleClick
*************************
With this new event it is possible to select isotope rows directly from the main window 


*************************
Form_Main
     MainListView1
*************************
Property "HideSelection" = False
Now the CPS printed is the same of the left scale CPS value

*************************
Form_Main
     ShowSelectedBinData
*************************
The function is completely rewritten



*************************
Form_Main
     Form_Load
*************************
        ' --------------------------------------------------------------------
	' Removed 6 lines
        ' ( Language is specified in the INI file and default is English )
        ' --------------------------------------------------------------------
        'Select Case Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName
        '    Case "ja"
        '        Language = "Japanese"
        '    Case "it"
        '        Language = "Italian"
        'End Select


*************************
 Class Spectrometer
    Sub txt_LinMax_TextChanged
    Sub txt_Lin_TextChanged
    Sub txt_EqMax_TextChanged
    Sub txt_Eq_TextChanged
    Sub CreateHeightCurve
    Sub CreateLinearityCurve()
    Sub FillAllBinsWith
*************************
All those functions are new or modifyed
There are 2 new TextBoxes for "Max effect"
There are 16 new TextBox for "band energy"
The button "Test" is "Visible" (useful to test equalizers)


*************************
 Class Spectrometer
	Sub DrawSelectedBin()
*************************
  Changed the top of the red line to make more visible the isotope lines
  The new position is:  mTopSpace + 32


*************************
 Class Spectrometer
*************************

    The flag "IsotopeEdited" is no longer required. 
    REMOVED DECLARATION AND 3 lines 

    Private Function CalcFWHM_NearTo(ByVal bin As Int32) As Int32
        Dim bin1 As Int32 = bin - 10  <<< 10 instead of 20
        Dim bin2 As Int32 = bin + 10  <<< 10 instead of 20


    ' =========================================================================================================
    '  Selected Isotopes Array (velocizes isotope marker drawing)
    ' =========================================================================================================
    Friend IsotopeListChanged As Boolean    
    Friend Structure Isotope
        Friend Name As String
        Friend Energy As Single
    End Structure
    Friend SelectedIsotopes(-1) As Isotope

    Friend Sub Fill_IsotopeList_and_SelectedIsotopesArray()
 	ReDim SelectedIsotopes(-1)
        Form_Main.MyListView1.Sort()
        Dim it As ListViewItem
        Dim ss As String = ""
        For Each it In Form_Main.MyListView1.Items
            If it.Text.Contains("=") Then it.Text = it.Text.Substring(0, it.Text.IndexOf("="))
            If it.SubItems(1).Text.Contains(",") Then it.SubItems(1).Text = it.SubItems(1).Text.Replace(",", ".").Trim
            If it.Checked Then
                ss = it.SubItems(1).Text.Replace(",", ".").Trim
                If ss = "" Then Exit For
                If IsNumeric(ss) Then
                    Dim index As Int32 = SelectedIsotopes.Length
                    ReDim Preserve SelectedIsotopes(index)
                    SelectedIsotopes(index).Name = it.Text
                    SelectedIsotopes(index).Energy = CSng(ss)
                End If
            End If
        Next
        ' --------------------------------------------------------- sort the array for crescent energy
        Array.Sort(SelectedIsotopes, AddressOf IsotopeComparer)
    End Sub

    Private Function IsotopeComparer(ByVal i1 As Isotope, ByVal i2 As Isotope) As Integer
        Return Math.Sign(i1.Energy - i2.Energy)
    End Function

    ' =========================================================================================================
    '   Mark Isotopes
    ' =========================================================================================================
    Private Sub MarkIsotopes()
        If IdentiFinder IsNot Nothing AndAlso IdentiFinder.Enabled Then
            IdentiFinder.MarkIsotopes(mGraphics)
        Else
	    If IsotopeListChanged Then
                IsotopeListChanged = False
                Fill_IsotopeList_and_SelectedIsotopesArray()
            End If
            For i As Int32 = 0 To SelectedIsotopes.Length - 1
                MarkIsotope(SelectedIsotopes(i).Name, SelectedIsotopes(i).Energy)
            Next
        End If
    End Sub

*************************
Form_Main
*************************
    NEW SUB: MyListView1_Click
    Private Sub MyListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyListView1.Click
        Spectrometer.IsotopeListChanged = True
    End Sub

    Sub MyListView1_AfterLabelEdit
         NEW LINE: Spectrometer.IsotopeListChanged = True

*************************
Module SaveLoad
    Sub SaveLoad_INI
       At the end of "Load finalize"
*************************
    Spectrometer.Fill_IsotopeList_and_SelectedIsotopesArray()


*************************
Module SaveLoad
    Sub SaveLoad_INI
*************************
saving also the TAB INDEX
    IV("TabIndex", Form_Main.TabControl1.SelectedIndex)


*************************
Form_Main
*************************
    TabControl1.Height 426 instead of 428

    ' Form Load (called TabControl1_Resize and modified comment)

 	' ------------------------------------------- Resize TabControl1 and UserText
        TabControl1_Resize()
        txt_UserText.SelectionStart = 9999
        txt_UserText.SelectionLength = 0
        txt_UserText.Focus()

    
    ' Two new SUB in the section "OPTION-TAB PROPERTIES"

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        TabControl1_Resize()
    End Sub

    Private Sub TabControl1_Resize()
        Select Case TabControl1.SelectedIndex
            Case 0
                TabControl1.Height = GroupBox_Params.Bottom + 28
                txt_UserText.Visible = True
            Case 1
                TabControl1.Height = GroupBox_GaussianDec.Bottom + 28
                txt_UserText.Visible = False
            Case 2
                TabControl1.Height = ClientSize.Height - TabControl1.Top - 28
                txt_UserText.Visible = False
        End Select
        TabControl1.Refresh()
    End Sub

*************************
Form_Main - VISUAL
*************************

   New "Gaussian deconvolution" PANEL with ENABLE / LABELS / TEXTBOX

   SaveLoad for ENABLE / LABELS / TEXTBOX

   Language files for PANEL / ENABLE / LABELS / TEXTBOX


**********************************
Form_Main - ShowSelectedBinData
**********************************
       ' ------------------------------------------------------- corrected CPS
            Dim s As String = (0.5 * Spectrometer.mValues(Spectrometer.SelectedBin) / TotalSeconds).ToString("0.0")
            If s.Length < 7 Then s &= "       ".Substring(0, 7 - s.Length)
            s = s.Substring(0, 7)
            StatusLabel2.Text = "Selected Bin=" & Spectrometer.SelectedBin.ToString & _
                                "  Energy=" & Spectrometer.SelectedEnergy.ToString("0.0 KeV") & _
                                "  Samples=" & nn.ToString("0") & _
                                "  cps=" & s



**********************************
 Super Gaussian Deconvolution
**********************************
New module "MatrixFunctions"

in the class Spectrometer the sub ApplyFilter is completely rewritten.


*************************
Form_Equalizers
************************* 
Restored the normal Enable Disable controls (it was commented - why?)
And added the new controls in the following functions:
EnableDisableControls
EnableLinControls
EnableEqControls


**********************************
Form_Main
**********************************
New checkbox "chk_OnlySelectedRows" and all the code to save/load and use it. 

With "OnlySelectedRows" the CPS of each selected row is sent to a different slot.
Using this with the new SuperDeconvolution can send the exact Bequerels to slots.


**********************************
 Module_MemoryMappedFiles
**********************************
"Module_MemoryMappedFiles" has been substituted with the new "Class_ThereminoSlots"
With the new class two functons are removed from Module_SaveLoad
and access to slots is different:
"MMF1.WriteSingle(SlotNumber * 4, ..." 
becomes: 
"Slots.WriteSlot(SlotNumber, ..."



